Fonts and font/point/line size

Elizabeth King
Kevin Middleton

Everything in a figure needs to be readable

  • Text
  • Labels
  • Lines
  • Colors and gradients

Adjusting fonts

Adding fonts

library(showtext)
font_add_google("Titan One", "titan")

# Use showtext automatically
showtext_auto()

ggplot(tibble(x = rnorm(1e3)), aes(x)) + geom_density() +
  labs(title = "Fancy font title") +
  theme(text = element_text(family = "titan"))

Adding fonts

Local fonts

  • Use full local path to font file
  • Provide italic, bold, and bolditalic if needed.
font_add(family = "times",
         regular = "/System/Library/Fonts/Supplemental/Times New Roman.ttf")

ggplot(tibble(x = rnorm(1e3)), aes(x)) + geom_density() +
  labs(title = "Fancy font title") +
  theme(text = element_text(family = "times"))

Local fonts

Adjusting font sizes

  • Use theme(axis.text...), etc. one by one
  • Use cowplot::theme_cowplot(font_size = X) to get pretty close
    • Options to change font face and relative sizes of axis labels, etc.
ggplot(tibble(x = rnorm(1e3)), aes(x)) + geom_density() +
  theme_cowplot(font_size = 10, font_family = "mono")

Adjusting font sizes

Manuscipt font size

  • font_size of 8 or 10 might be fine for manuscript figures
  • Figures will look terrible in RStudio plot preview
  • Save to file, open, print
    • Repeat
    • Set up a reusable figure theme

Slide font size

  • font_size of 20, 24, or larger might be necessary for slide figures
  • Figures will look terrible in RStudio plot preview
  • Save to file (jpg/png) at expected output size
    • Draw a box in powerpoint and get dimensions

Slide font size

Slide font size

ggplot(tibble(x = rnorm(1e3)), aes(x)) + geom_density() +
  theme_cowplot(font_size = 24, font_family = "serif")

Slide font size

Adjusting point and line size

  • Same as for font sizes
    • Export, print/import, check
    • Repeat